
import { serviceGetUserInfo } from '@/services/user';

export default {
  namespase: 'user',
  state: {
    userInfo: null,
  },
  effects: {
    /**
     * @name 获取用户信息,并更新仓库状态,返回用户信息
     */
    *getUserInfo(_, { put, call }) {
      try {
        const { success, data } = yield call(serviceGetUserInfo);
        if (!success) {
          return false;
        }
        yield put({
          type: 'update',
          userInfo: data,
        });
        return data;
      } catch (error) {
        //
      }
      return null;
    },
    logout() {
      // console.log('退出登录');
    },
  },
  reducers: {
    /* 更新状态（通用） */
    update: (state, { type, ...newState }) => ({
      ...state,
      ...newState,
    }),
  },
};
